package com.cxx.home.controller;

import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.password.PasswordDto;
import com.cxx.home.service.PasswordService;
import com.cxx.home.vo.PasswordQueryVo;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/password")
@Tag(name = "密码管理")
public class PasswordController {
    @Resource
    private PasswordService passwordService;

    @Operation(summary = "查询密码记录")
    @GetMapping("")
    public @JsonView(ReadView.class) List<PasswordDto> queryPassword(PasswordQueryVo query) {
        return passwordService.query(query);
    }

    @Operation(summary = "新增密码记录")
    @PostMapping("")
    public Boolean addPassword(@RequestBody @JsonView(WriteView.class) @Validated PasswordDto passwordDto) {
        return passwordService.add(passwordDto);
    }

    @Operation(summary = "更新密码记录")
    @PutMapping("/{id}")
    public Boolean updatePassword(@PathVariable("id") long id,
                                  @RequestBody @JsonView(WriteView.class) PasswordDto passwordDto) {
        return passwordService.update(id, passwordDto);
    }

    @Operation(summary = "删除密码记录")
    @DeleteMapping("/{id}")
    public Boolean deletePassword(@PathVariable("id") long id) {
        return passwordService.delete(id);
    }

    @Operation(summary = "查询密码记录类别")
    @GetMapping("/category")
    public List<String> queryPasswordCategory() {
        return passwordService.queryCategory();
    }
}
    